package com.ywk.base.dataStructure.algorithm;
//二叉搜索非递归算法
public class BinarySearchNoRecursion {

	public static void main(String[] args) {
		int[] nums= {1,5,8,15,33,56,64,88,100};
		System.out.println(binarySearch(nums, 100));
	}
	
	
	public static int binarySearch(int[] nums,int target) {
		int left=0;
		int right=nums.length-1;
		while(left<=right) {
			int mid=(left+right)/2;
			if(nums[mid]==target) {
				return mid;
			}else if(nums[mid]>target) {
				right=mid-1;
			}else {
				left=mid+1;
			}
		}
		return -1;
	}
}
